var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        top_height: 0,
        thetitle: "功能模块",
        parentId: "0",
        list: [],
        list_index: [],
        mod_checked: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that = this;
        wx.getSystemInfo({
            success(res) {
                console.log(res)
                that.setData({
                    top_height: res.statusBarHeight + 40
                })
                // that.top_height = res.statusBarHeight; //data中 声明 top_height:0 
            }
        });
        wx.removeStorage({
            key: 'mod',
        })
    },
    toback() {
        var _list_index = this.data.list_index
        var _parentId = this.data.parentId
        var _mod_checked = this.data.mod_checked
        if (_list_index.length > 0) {
            let parentId = _list_index.pop()
            if (parentId == _parentId) {
                parentId = _list_index.pop()
            }
            this.getModList(parentId)
        } else {
            wx.setStorage({
                key: "mod",
                data: _mod_checked,
            })
            wx.navigateBack({
                delta: 1,
            })
        }
    },
    onShow() {
        wx.hideHomeButton({
            success: (res) => {},
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        this.getModList(this.data.parentId)
    },
    bindRadioCheck(e) {
        this.setData({
            mod_checked: e.detail.value
        })
    },
    bindModList(e) {
        // console.log(e.target.dataset.key)
        var _list_index = this.data.list_index
        _list_index.push(e.target.dataset.key)
        this.setData({
            list_index: _list_index,
            parentId: e.target.dataset.key
        })
        this.getModList(e.target.dataset.key)
    },
    getModList(parentId) {
        var _list = wx.getStorageSync(parentId)
        if (_list) {
            this.setData({
                list: _list
            })
            return
        }
        let _this = this;
        app.postData("/business/busModule/list3/" + parentId, null).then(res => {
            console.log(res.data.data)
            var _list = []
            try {
                if (res.data.code == 0) {
                    res.data.data.forEach(element => {
                        var list = {
                            "key": element.modId,
                            "value": element.modName
                        }
                        _list.push(list)
                    });
                    _this.setData({
                        list: _list
                    })
                    wx.setStorage({
                        key: parentId,
                        data: _list,
                    })
                } else {
                    wx.showToast({
                        icon: 'error',
                        title: res.data.msg,
                    })
                }
            } catch (e) {
                wx.showToast({
                    icon: 'error',
                    title: '获取信息失败',
                })
            }

        })
    },
})
// 功能模块
// public static String URL_BUSMODULE = getMethod("/business/busModule/list3");